package cn.skyquant.quant4j.service.boot.web.controller;

import cn.skyquant.quant4j.api.dto.ResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.WebRequest;

import java.util.Map;

@RestController
public class ErrController implements ErrorController {
    @Autowired
    ErrorAttributes errorAttributes;

    @RequestMapping(value = "/error")
    public ResultDTO<Map> error(WebRequest webRequest) {
        Map<String, Object> map = errorAttributes.getErrorAttributes(webRequest, false);
        return ResultDTO.error("error",map);
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}
